/*
  ODASiren.cpp - 
*/

#include "ODASiren.h"
#include "ODPort.h"
#include "WProgram.h"
#include "ODADebug.h"

Siren::Siren() {
  return;
}

void Siren::init(uint8_t pin, uint8_t type) {
  _type = type;
  if (_type == GENERIC_OUTDOOR) {
    _off = HIGH;
    _on = LOW;
  } else if (_type == GENERIC_INDOOR) {
    _off = LOW;
    _on = HIGH;
  }
  _port.initOutput(pin, _off);
  _status = _off;
  _stopTime = 0;
}

void Siren::startAlarm() {
  if (_status == _off) {
    _status = _on;
    _port.setStatus(_status);
    _stopTime = millis() + 30000;
  }
}

void Siren::stopAlarm() {
  _status = _off;
  _port.setStatus(_status);
  _stopTime = 0;
}

void Siren::service() {
  if (_status == _on && millis() > _stopTime)
    stopAlarm();
}